package com.emm.yixun.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 
 * <p>Sequences 生成工具</p>
 */
public class SequencesGenerator {
    private static AtomicInteger atom = new AtomicInteger();

    /**
     * @param prefix 标识前缀
     * @return
     */
    public static String getUniqueSequences(String prefix) {
        //TODO 获得分布式下机器的节点number mock
        int node = 1;
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String time = format.format(new Date());
        int suffix = atom.getAndIncrement();
        return prefix.toUpperCase() + "-" + time + "-" + suffix + "-" + node;
    }

    /**
     * 获取UUID
     * @return
     */
    public static String getUUID(String prefix) {
        return prefix + UUID.randomUUID().toString().replace("-", "");
    }

}
